package com.rd.teacher.jichao.day12;

public class TestBank extends Thread {

    // 银行类需要有账户来取钱
    // Bank has a Account  构成一个类的组合关系
    Account account;
    // 取钱的金额
    double money;

    public TestBank(String name, Account account, double money) {
        super(name);
        this.account = account;
        this.money = money;
    }

    @Override
    public void run() {
        // 取钱的操作
        if (account.balance < money) {
            System.out.println("余额不足");
            return;
        }

        System.out.println(getName() + " 可以取钱");
        // 建议使用get set
        account.balance = account.balance - money;
        System.out.println("取钱后的余额为：" + account.balance);

    }

    public static void main(String[] args) {
        Account account = new Account("123456",888);
        new TestBank("zhangsan",account,666).start();
        new TestBank("lisi",account,666).start();
    }
}

// 创建一个账户类
class Account {
    // 属性设置为账户id和余额
    String accountId;
    double balance;

    // 创建构造器 ctrl+N
    // 选择 constructor构造器 按住shift选择两个属性 ok
    public Account(String accountId, double balance) {
        this.accountId = accountId;
        this.balance = balance;
    }

}